package com.feisuanyz.lyweb01.service.impl;

import com.feisuanyz.lyweb01.dao.UserCaseMapper;
import com.feisuanyz.lyweb01.pojo.domain.UserCaseDO;
import com.feisuanyz.lyweb01.pojo.dto.UserCaseDTO;
import com.feisuanyz.lyweb01.pojo.query.UserCaseQuery;
import com.feisuanyz.lyweb01.pojo.vo.PageResult;
import com.feisuanyz.lyweb01.service.UserCaseService;
import java.lang.Boolean;
import java.lang.Override;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.Date;

/**
 * 用户案例的实现
 *
 * @author deng
 * @date 2025-02-26 11:57:37
 */
@Service
public class UserCaseServiceImpl implements UserCaseService {

    @Autowired
    private UserCaseMapper userCaseMapper;

    @Override
    public PageResult<UserCaseDO> getUserCaseList(UserCaseQuery userCaseQuery) {
        IPage<UserCaseDO> page = new Page<>(userCaseQuery.getPageIndex(), userCaseQuery.getPageSize());
        IPage<UserCaseDO> userCasePage = userCaseMapper.selectPage(page, Wrappers.emptyWrapper());
        PageResult<UserCaseDO> pageResult = new PageResult<>(userCasePage);
        return pageResult;
    }

    @Override
    public UserCaseDO getUserCaseDetail(UserCaseQuery userCaseQuery) {
        UserCaseDO userCaseDO = userCaseMapper.selectById(userCaseQuery.getCaseId());
        return userCaseDO;
    }

    @Override
    public Boolean addUserCase(UserCaseDTO userCaseDTO) {
        UserCaseDO userCaseDO = new UserCaseDO();
        userCaseDO.setCaseTitle(userCaseDTO.getCaseTitle());
        userCaseDO.setCaseDescription(userCaseDTO.getCaseDescription());
        userCaseDO.setCaseImageUrl(userCaseDTO.getCaseImageUrl());
        userCaseDO.setCreateBy(userCaseDTO.getCreateBy());
        userCaseDO.setCreateTime(new Date());
        int result = userCaseMapper.insert(userCaseDO);
        return result > 0;
    }

    @Override
    public Boolean updateUserCase(UserCaseDTO userCaseDTO) {
        UserCaseDO userCaseDO = new UserCaseDO();
        userCaseDO.setCaseId(userCaseDTO.getCaseId());
        userCaseDO.setCaseTitle(userCaseDTO.getCaseTitle());
        userCaseDO.setCaseDescription(userCaseDTO.getCaseDescription());
        userCaseDO.setCaseImageUrl(userCaseDTO.getCaseImageUrl());
        userCaseDO.setUpdateBy(userCaseDTO.getUpdateBy());
        userCaseDO.setUpdateTime(new Date());
        int result = userCaseMapper.updateById(userCaseDO);
        return result > 0;
    }

    @Override
    public Boolean deleteUserCase(UserCaseDTO userCaseDTO) {
        int result = userCaseMapper.deleteById(userCaseDTO.getCaseId());
        return result > 0;
    }
}
